<?php

/**
 * Gets all fusion models uploaded
 * @package ModuleGestionDocuments
 * @version 1.0b
 * @return table
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

$model = new Model();
$modelList = $model->GetList(); ?>

<table cellpadding="0" cellspacing="0" border="0" class="table-objects">
	<tr>
		<th class="check"></th>
		<th>Fichier</th>
		<th>Auteur</th>
		<th>Ajouté le</th>
	</tr>
	<?php foreach ($modelList as $model) {
		$crmuser = $model->GetCrmuser();
		$crmcontact = $crmuser->GetContact();
		$date = explode('-', $model->date);
		$date = $date[2].'/'.$date[1].'/'.$date[0];
		
		$res  = '<tr>';
		$res .= '<td class="check"><input name="all" type="radio" value="'.$model->modelId.'" /></td>';
		$res .= '<td><a href="'.$configuration['appdir'].'data/models/'.$model->modelId.'.'.$model->extension.'" target="_blank" class="file">'.$model->filename.'.'.$model->extension.'</a></td>';
		$res .= '<td><a href="crmusers.php?id='.$crmuser->crmuserId.'&operation=edit">'.$crmcontact->lastname.' '.$crmcontact->firstname.'</a></td>';
		$res .= '<td>'.$date.'</td>';
		$res .= '</tr>';
		echo $res;
	} ?>
</table>